#ifndef HAIKUOS_SRC_APPS_TERMINAL_SHELL_H
#define HAIKUOS_SRC_APPS_TERMINAL_SHELL_H

#include "ShellInfo.h"

struct AcitiveProcessInfo;
struct ShellParameters;
// TODO: maybe merge TermParse and Shell classes ?
struct TerminalBuffer;
struct TermParse;

struct Shell
{
    Shell();
    virtual ~Shell();

    status_t Open(int row, int col, const ShellParameters &parameters);

    void Close();

    const char *TTYName() const;

    ssize_t Read(void *buffer, size_t numBytes) const;
    ssize_t Write(const void *buffer, size_t numBytes);

    status_t UpdateWindowSize(int row, int col); // TODO: rename

    status_t GetAttr(struct termios &attr) const;

    status_t SetAttr(const struct termios &attr);

    int FD() const;

    pid_t ProcessID() const
    {
        return fShellInfo.ProcessID();
    }

    const ShellInfo &Info() const
    {
        return fShellInfo;
    }

    int Encoding() const
    {
        return fShellInfo.Encoding();
    }

    void SetEncoding(int encoding)
    {
        fShellInfo.SetEncoding(encoding);
    }

    bool HasActiveProcesses() const;

    bool GetActiveProcessInfo(ActiveProcessInfo &info) const;

    virtual status_t AttachBuffer(TerminalBuffer *buffer);
    virtual void DetachBuffer();

private:
    status_t _Spawn(int row, int col, const ShellParameters &params);

private:
    // TODO: why use f to prefix something
    ShellInfo fShellInfo;
    int fFd;
    pid_t fProcessID;
    TermParse fTermParse;
    bool fAttached;
};

#endif // header file protect
       // END: CODEREVIEW: